﻿using System.Text.RegularExpressions;
using System;

namespace FileSquirrel.Logic
{
    public class FileNameHelper
    {
        private string _show;
        private string _season;
        private string _episode;

        public FileNameHelper(string FileName)
        {
            if (Regex.IsMatch(FileName, @"(.*?)\s*-*\s*[sS](\d+)[eE](\d+).*?"))
            {
                _show = Regex.Match(FileName, @"(.*?)\s*-*\s*[sS](\d+)[eE](\d+).*?").Groups[1].Value;
                _season = Regex.Match(FileName, @"(.*?)\s*-*\s*[sS](\d+)[eE](\d+).*?").Groups[2].Value;
                _episode = Regex.Match(FileName, @"(.*?)\s*-*\s*[sS](\d+)[eE](\d+).*?").Groups[3].Value;
            }
            else if (Regex.IsMatch(FileName, @"(.*?)\s*-*\s*(\d+)x(\d+).*?"))
            {
                _show = Regex.Match(FileName, @"(.*?)\s*-*\s*(\d+)x(\d+).*?").Groups[1].Value;
                _season = Regex.Match(FileName, @"(.*?)\s*-*\s*(\d+)x(\d+).*?").Groups[2].Value;
                _episode = Regex.Match(FileName, @"(.*?)\s*-*\s*(\d+)x(\d+).*?").Groups[3].Value;
            }
            else if (Regex.IsMatch(FileName, @"(.*?)\s*-*\s*(\d*)(\d\d).*?"))
            {
                _show = Regex.Match(FileName, @"(.*?)\s*-*\s*(\d*)(\d\d).*?").Groups[1].Value;
                _season = Regex.Match(FileName, @"(.*?)\s*-*\s*(\d*)(\d\d).*?").Groups[2].Value;
                _episode = Regex.Match(FileName, @"(.*?)\s*-*\s*(\d*)(\d\d).*?").Groups[3].Value;
            }
        }

        #region Property Procedures
        public string Show
        {
            get { return _show; }
            set { _show = value; }
        }

        public string Season
        {
            get
            {
                return
                    "Season " + (string.IsNullOrEmpty(_season) ? 0 : Convert.ToInt32(_season));
            }
            set { _season = value; }
        }

        public string Episode
        {
            get { return _episode; }
            set { _episode = value; }
        }
        #endregion
    }
}
